<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
body {
	background-color: #F5F5F5;
}
form.comps4 {
	background: -webkit-gradient(linear, bottom, left 175px, from(#CCCCCC), to(#EEEEEE));
	background: -moz-linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
	margin: auto;
	position: absolute;
	width: 730px;
	height: 250px;
	font-family: Tahoma, Geneva, sans-serif;
	font-size: 14px;
	font-style: italic;
	line-height: 24px;
	font-weight: bold;
	color: #000;
	text-decoration: none;
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;
	padding: 10px;
	border: 1px solid #999;
	border: inset 1px solid #333;
	-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
	-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
	box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
	top: -19px;
}
</style>
</head>

<body>
<div style="position: absolute; left: 1112px; top: 57px;">
<?php
$curr_month = date("m");
$month = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$dis="
<style type=text/css>
form.s4find {
background: -webkit-gradient(linear, bottom, left 175px, from(#CCCCCC), to(#EEEEEE));
background: -moz-linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
margin:auto;
position:absolute;
right:-200px;
width:390px;
height:30px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 14px;
font-style: italic;
line-height: 24px;
font-weight: bold;
color: #000;
text-decoration: none;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
padding:10px;
border: 1px solid #999;
border: inset 1px solid #333;
-webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);		
}
input.submit2 {
	width: 100px;
	background: #666;
	color: #fff;
	font-family: Tahoma, Geneva, sans-serif;
	height: 30px;
	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	border-radius: 5px;
	border: 1p solid #999;
	background-color: #666;
}
</style>
<form class=s4find method=post action=mains4.php><table align=center><tr>
<td><select name=mnth>";
$k=1;
$q=$curr_month-1;
if($q<1){
	$q=12;
}
for($i=0; $i<12; $i++){
	if($k==$q){
		$dis.="<option value=$k selected=selected>$month[$i]</option>";
		$k++;
	}else{
	$dis.="<option value=$k>$month[$i]</option>";
		$k++;	
	}
}

$dis.="</select></td><td><select name=yr>";
$curr_yr=date("Y");
for($j=2010; $j<2099; $j++){
if($j==$curr_yr){
$dis.="<option value=$j selected=selected>$j</option>";	
}else{
$dis.="<option value=$j >$j</option>";	
}
}
$dis.="</select></td><td><input type=submit name=finds4 value=Search id=finds4 class=submit2 /></td>
</tr></table></form>";
print("$dis");	
?>
</div>
<div style="position: absolute; left: 15px; top: 140px;">
<?php
include("conn.php");
if(isset($_POST['finds4'])){
//the defined variables will contain a count of all publishers who submitted their reports between the 21st of the previous month and 20th of the next month
$pcnt=0;
$apcnt=0;
$rpcnt=0;
//these variables contain the total number of pubs who actually submitted on that month
$spcnt=0;
$sapcnt=0;
$srpcnt=0;
$pbk=0;
$pbklet=0;
$phrs=0;
$pmagz=0;
$prv=0;
$pbs=0;
$apbk=0;
$rpbk=0;
$apbklet=0;
$rpbklet=0;
$aphrs=0;
$rphrs=0;
$apmagz=0;
$aprv=0;
$apbs=0;
$rpmagz=0;
$rprv=0;
$rpbs=0;
$y2=0;
$mnth = array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$m=$_POST['mnth'];
$y=$_POST['yr'];
//$prvm=$m-1;
//if($prvm<1){
//$prvm=12;
//$y2=$y-1;
//}else{
//	$y2=$y;
//}
$l=$y."-".$m."-21";
$l1=strtotime($l);
$lodat=date('Y-m-d',$l1);
$nextm=$m+1;
if($nextm>12){
	$nextm=1;
	$y1=$y+1;;
}else{
	//$nextm=$m;
	$y1=$y;
}
$h=$y1."-".$nextm."-20";
$h1=strtotime($h);
$hidat=date('Y-m-d',$h1);
$s="select * from s4 where indate between '$lodat' and '$hidat'";
$r=mysql_query($s,$conn) or die(mysql_error());
if(mysql_num_rows($r)>0){
while($t=mysql_fetch_array($r)){
	$mn=$t['Month'];
	$yr=$t['yr'];
	$priv=$t['pubpriv'];
	if(($mn==$m) and ($yr==$y)){
		switch($priv){
			case 0:
			$pcnt++;
			$spcnt++;
			$pbk+=$t['bks'];
			$pbklet+=$t['bklets'];
			$phrs+=$t['hrs'];
			$pmagz+=$t['magz'];
			$prv+=$t['rvisits'];
			$pbs+=$t['bstudy'];
			break;
			case 1:
			$apcnt++;
			$sapcnt++;
			$apbk+=$t['bks'];
			$apbklet+=$t['bklets'];
			$aphrs+=$t['hrs'];
			$apmagz+=$t['magz'];
			$aprv+=$t['rvisits'];
			$apbs+=$t['bstudy'];
			break;
			case 2:
			$rpcnt++;
			$srpcnt++;
			$rpbk+=$t['bks'];
			$rpbklet+=$t['bklets'];
			$rphrs+=$t['hrs'];
			$rpmagz+=$t['magz'];
			$rprv+=$t['rvisits'];
			$rpbs+=$t['bstudy'];
			break;
			default:
			break;
			
		}
	}else{
		switch($priv){
			case 0:
			$pcnt++;
			//$spcnt++;
			$pbk+=$t['bks'];
			$pbklet+=$t['bklets'];
			$phrs+=$t['hrs'];
			$pmagz+=$t['magz'];
			$prv+=$t['rvisits'];
			$pbs+=$t['bstudy'];
			break;
			case 1:
			$apcnt++;
			//$sapcnt++;
			$apbk+=$t['bks'];
			$apbklet+=$t['bklets'];
			$aphrs+=$t['hrs'];
			$apmagz+=$t['magz'];
			$aprv+=$t['rvisits'];
			$apbs+=$t['bstudy'];
			break;
			case 2:
			$rpcnt++;
			//$srpcnt++;
			$rpbk+=$t['bks'];
			$rpbklet+=$t['bklets'];
			$rphrs+=$t['hrs'];
			$rpmagz+=$t['magz'];
			$rprv+=$t['rvisits'];
			$rpbs+=$t['bstudy'];
			break;
			default:
			break;
			
		}
	}
}

$tallsubs=$pcnt+$apcnt+$rpcnt;
$tcsubs=$spcnt+$sapcnt+$srpcnt;
$lp=$pcnt-$spcnt;
$lap=$apcnt-$sapcnt;
$lrp=$rpcnt-$srpcnt;
$tl=$lp+$lap+$lrp;
$tbks=$apbk+$rpbk+$pbk;
$tbklets=$apbklet+$pbklet+$rpbklet;
$thrs=$phrs+$aphrs+$rphrs;
$tmagz=$pmagz+$apmagz+$rpmagz;
$trv=$prv+$aprv+$rprv;
$tbs=$pbs+$apbs+$rpbs;
$b=$m-1;
$disp="
<h2 align=center>$mnth[$b] $y Composite S4 Report for Maridale Congregation</h2>
<div align=center>
<style type=text/css>
table {
	align: center;
	
}
table.imagetable {

	font-family: verdana,arial,sans-serif;
	font-size:14px;
	color:#333333;
	border-width: 1px;
	border-color: #999999;
	border-collapse: collapse;
}
table.imagetable th {
	background:#b5cfd2 url(cell-blue.jpg);
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #999999;
}
table.imagetable td {
	background:#dcddc0 url(cell-grey.jpg);
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #999999;
}
</style>
<form class=comps1 ><table class=imagetable align=center>
<tr align=left>
	<th></th>
	<th>All Submissions</th>
	<th>Late Submissions</th>
	<th>$mnth[$b] $y Submissions</th>
	<th>Books</th>
	<th>Booklets</th>
	<th align=center>Hours</th>
	<th>Magazine</th>
	<th>Return Visits</th>
	<th>Bible Study</th>
</tr>
<tr>
<td align=right>Publisher</td>
<td align=center>$pcnt</td>
<td align=center>$lp</td>
<td align=center>$spcnt</td>
<td align=center>$pbk</td>
<td align=center>$pbklet</td>
<td align=center>$phrs</td>
<td align=center>$pmagz</td>
<td align=center>$prv</td>
<td align=center>$pbs</td>
</tr>
<tr>
<td align=right>Auxillary Pioneer</td>
<td align=center>$apcnt</td>
<td align=center>$lap</td>
<td align=center>$sapcnt</td>
<td align=center>$apbk</td>
<td align=center>$apbklet</td>
<td align=center>$aphrs</td>
<td align=center>$apmagz</td>
<td align=center>$aprv</td>
<td align=center>$apbs</td>
</tr>
<tr>
<td align=right>Regular Pioneer</td>
<td align=center>$rpcnt</td>
<td align=center>$lrp</td>
<td align=center>$srpcnt</td>
<td align=center>$rpbk</td>
<td align=center>$rpbklet</td>
<td align=center>$rphrs</td>
<td align=center>$rpmagz</td>
<td align=center>$rprv</td>
<td align=center>$rpbs</td>
</tr>
<tr>
<td align=right><strong>Grand Totals:</strong></td>
<td align=center><strong>$tallsubs</strong></td>
<td align=center><strong>$tl</strong></td>
<td align=center><strong>$tcsubs</strong></td>
<td align=center><strong>$tbks</strong></td>
<td align=center><strong>$tbklets</strong></td>
<td align=center><strong>$thrs</strong></td>
<td align=center><strong>$tmagz</strong></td>
<td align=center><strong>$trv</strong></td>
<td align=center><strong>$tbs</strong></td>
</tr></table></form>
";
print("$disp");
print("<div align=left><strong><br>Please Note:</strong><br>1.	The above Report is based on reports submitted between $lodat and $hidat<br>2.	Late Submissions Are those reports submitted between the above specified date but from previous months</div>");
}else{
//put code to show that no record was found	
echo "<font color=green><strong>No Submissions for the specified Month have been found!!!</strong></font>";
}
}
?></div>
</body>
</html>